package com.example.reagent_management.ui.operatedialog.adapter

import android.annotation.SuppressLint
import androidx.recyclerview.widget.DiffUtil
import com.example.lib_base.adapter.BasePagingAdapter
import com.example.lib_base.utils.DateConvertUtils
import com.example.reagent_management.R
import com.example.reagent_management.room.entity.InStoreChoose

class InStoreChooseAdapter : BasePagingAdapter<InStoreChoose>(object : DiffUtil.ItemCallback<InStoreChoose>() {
    override fun areItemsTheSame(oldItem: InStoreChoose, newItem: InStoreChoose): Boolean {
        return oldItem.id == newItem.id
    }

    @SuppressLint("DiffUtilEquals")
    override fun areContentsTheSame(oldItem: InStoreChoose, newItem: InStoreChoose): Boolean {
       return oldItem == newItem
    }
}) {
    override fun getItemLayout(position: Int): Int {
        return R.layout.item_in_store_choose
    }

    override fun bindData(helper: ItemHelper, data: InStoreChoose?) {
        if (data != null) {
            with(helper){
                setText(R.id.batch,data.batch)
                if (System.currentTimeMillis() > data.days){
                    setText(R.id.times,"已过期")
                }else{
                    setText(R.id.times, DateConvertUtils.convertTimeToStringCH(data.days,"yyyy-MM-dd HH:mm:ss"))
                }
                setText(R.id.inCounts,data.inCounts.toString())
                setText(R.id.supplier,data.supplier?:"-")
            }
        }
    }

    override fun getClickViewId(): Array<Int>? {
        return null
    }

}